package com.example.sendsms.utils;

import static android.content.pm.PackageManager.PERMISSION_DENIED;

import android.app.Activity;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class PermissionUtil {
    public static boolean requestPermission(Activity context, int requestCode, String[] systemPermissions) {

        if (systemPermissions==null) {
            return false;
        }

        for (String contactsPermission : systemPermissions) {

            // 检查是否已经有次权限
            if (ContextCompat.checkSelfPermission(context,contactsPermission)==PERMISSION_DENIED) {

                // 权限缺失，请求权限
                ActivityCompat.requestPermissions(context,systemPermissions,requestCode);
                return false;
            }
        }

       // Toast.makeText(context, "已授权成功", Toast.LENGTH_SHORT).show();

        return true;
    }
}
